<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录</title>
    <style>
        .login {
            width: 400px;
            margin: 100px auto;
        }

        .box {
            width: 400px;
            border: 1px solid #ccc;
            height: 400px;
            display: none;
        }

        ul {
            display: flex;
            justify-content: center;
            list-style: none;
            width: 400px;
            height: 30px;
            border: 1px solid #ccc;
            margin: 0;
            padding: 0;
            line-height: 30px;
        }

        ul li {
            margin: 0 10px;
            color: #ccc;
            cursor: pointer;
        }

        .box img {
            width: 70px;
            margin: 0 10px;
        }

        .img {
            display: flex;
            justify-content: center;

        }

        .li {
            color: black;
        }

        .box p {
            text-align: center;
            color: #ccc;
            margin-top: 40px;
        }

        /* .box1{
            width: 300px;
            border:1px solid #ccc;
            height: 300px;
        } */
        .box input {
            width: 240px;
            height: 30px;
            box-sizing: border-box;
        }

        .box input:nth-of-type(1) {
            margin: 50px 26px 10px 78px;
        }

        .box input:nth-of-type(2) {
            margin: 0 26px 26px 78px;
        }

        button {
            width: 240px;
            height: 30px;
            background: rgb(84, 177, 240);
            border: rgb(84, 177, 240);
            margin: 0 26px 0 78px;
            padding: 0;
        }

        .current {
            display: block;
        }

        .img dl {
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="login">
        <ul>
            <li class="li">快速登录</li>
            <li>账号密码登录</li>
        </ul>
        <div id="box" class="box current">
            <p>请扫描二维码，或点击头像登录</p>
            <div class="img">
                <dl>
                    <dl><img src="./images/2.jpg"></dl>
                    <dt>安全登录</dt>
                </dl>
                <dl>
                    <dl><img src="./images/1.jpg"></dl>
                    <dt>安全登录</dt>
                </dl>
            </div>
        </div>
        <div id="box" class="box">
<form>
            <input name="uname" placeholder="用户名">
            <input name="upwd" placeholder="密码">
            <button>登录</button>
</form>
        </div>
    </div>
    <script>
        var oLis = document.querySelectorAll("li");
        var oBoxs = document.querySelectorAll("#box");
        for (var i = 0; i < oLis.length; i++) {
            oLis[i].onclick = fn(i);
        }
        function fn(tempIndex) {
            return function (evt) {
                oLis.forEach(function (item, index) {
                    item.className = tempIndex == index ? 'li' : '';
                    oBoxs[index].className = tempIndex == index ? 'box current' : 'box';
                })
            }
        }
        document.forms[0].onsubmit = function () {
            //1.获取本地数据
            var oUserList = JSON.parse(localStorage.getItem("user") || '[]');
            //2.用户名和密码
            var oUser = {
                uname: this.uname.value,
                upwd: this.upwd.value
            }
            //3. 比较
            var isLogin = false; //默认登录失败
            for (var i = 0; i < oUserList.length; i++) {
                if (oUserList[i].uname === oUser.uname && oUserList[i].upwd === oUser.upwd) {
                    isLogin = true;
                    break;
                }
            }
            //4. 如果存在,就把当前用户信息,保存到
            //sessionStorage
            if (isLogin) {
                sessionStorage.setItem("user", JSON.stringify(oUser));
                alert("登录成功!")
                location = "./list.html";
            } else {
                alert("用户名或密码错误!")
            }
            return false;
        }
    </script>
</body>

</html>